package com.itheima.controller;

import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/checkitem")
@Slf4j
public class CheckItemController {

    @Autowired
    private CheckItemService checkItemService;

    @PostMapping("/add")
    public Result add(@RequestBody CheckItem checkItem){
        log.info("添加项目");
        checkItemService.add(checkItem);
        return new Result(true,"添加成功");
    }

    //分页查询检查项目管理
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        log.info("分页查询项目");
        return checkItemService.findPage(queryPageBean);

    }
    @GetMapping("/delete")
    public Result delete(Integer id){
        log.info("删除项目");
        checkItemService.delete(id);
        return new Result(true,"删除成功");
    }
    @PostMapping("/edit")
    public Result edit(@RequestBody CheckItem checkItem){
        log.info("编辑项目");
        checkItemService.edit(checkItem);
        return new Result(true,"编辑成功");
    }
    @GetMapping("/findById")
    public Result findById(Integer id){
        log.info("编辑项目");
        CheckItem checkItem = checkItemService.findById(id);
        return new Result(true,"编辑成功",checkItem);
    }
    @GetMapping("/findAll")
    public Result findAll(){
        log.info("查询所有项目");
        return new Result(true,"查询成功",checkItemService.findAll());
    }
    @GetMapping("findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(Integer id){
        log.info("查询所有项目");
        return new Result(true,"查询成功",checkItemService.findCheckItemIdsByCheckGroupId(id));
    }
}
